<style type="text/css">
	div.tab-con{
		font-size:14px;
		color:#4F5356;
		text-align:center;
		margin:40px 120px 10px;
	}
	table.set-con{
		width:100%;
		border-collapse:collapse;
		table-layout:fixed;
	}
	.set-con-long{
		width:20%;
		overflow:hidden;
		text-overflow:ellipsis;
		white-space:nowrap;
	}
	.set-con-short{
		width:15%;
	}
	.boder-tr{
		border-bottom:1px solid #E7E7E7;
		height:40px;
		line-height:40px;
		background-color:#F4F4F4;
	}
	.table-height{
		height:40px;
		line-height:40px;
		border-bottom:1px solid #E7E7E7;
	}
	ul.ul-bottom{
		height:30px;
		border-bottom:1px solid #DDD;
	}
	/*1080p*/
	@media screen and (min-device-width:1920px){
		div.tab-con {
			font-size: 18px;
		}
	}
</style>
<script type="text/javascript">
(function(){
	<%
		local para = {
			upnp = {config = {}, upnp_list = {}}
		}

		local data = tpl_get_data(para, true)
	-%>

	var upnpInfo = <%=data%>;

	function init(result){
		var errNo = result[ERR_CODE];
		var ret;
		if (E_NONE == errNo){
			ret = result[K_MODULE];
		}else{
			console.log(result);
			return;
		}

		var upnp = ret.upnp.config;

		initSwitch("UpnpSwitch", upnp.enable, function(state,init){
			if (1 == state){
				$("#UpnpTab").show();
			}else{
				$("#UpnpTab").hide();
			}

			if (!init){
				var data = {};
				var para = {};
				para.upnp = {};
				para.upnp.config = data;
				data["enable"]=$("#UpnpSwitch").attr("data-value");
				showLoading(label.saving);
				apiSet(para, function(ret){
					$.setTimeout(function(){
						stateman.go("pc.UPnPApp");
					}, 2000);
				});
			}
		});

		var upnpList = ret.upnp.upnp_list.list;
		for (var i = 0; i < upnpList.length; i++){
			$("#UpnpTable").append(initUpnPEntry(upnpList[i]));
		}
	}

	init(upnpInfo);

	function initUpnPEntry(client){
		if ("1" == client.status){
			client.status = label.open;
		}else{
			client.status = label.close;
		}

		return  '<tr class="table-height">' +
					'<td class="set-con-long" title="' + client.descript + '">' + client.descript + '</td>' +
					'<td class="set-con-long">' + client.protocol + '</td>' +
					'<td class="set-con-long">' + client.external_port + '</td>' +
					'<td class="set-con-long">' + client.internal_port + '</td>' +
					'<td class="set-con-long">' + client.ip + '</td>' +
					'<td class="set-con-long">' + client.status + '</td>' +
				'</tr>';
	}
})();
</script>
<div class="help hidden">
	<ul class="help-content">
		<li class="help-head">
			<img class="app-icon" src="/luci-static/images/app-icon/upnp.png?_=20170809165512" />
			<span class="help-title">{%label.UpnpSet%}</span>
		</li>
		<li class="summary">{%helpStr.upnp%}</li>
	</ul>
</div>
<div class="head-con">
	<img class="app-icon" src="/luci-static/images/app-icon/upnp.png?_=20170809165512" />
	<a href="javascript:history.go(-1);" class="head-btn-l">
		<i class="head-btn icon icon_back"></i>
		<span class="head-title">{%label.UPnP%}</span>
	</a>
</div>
<div class="set-con below-head">
	<ul id="UpnpEnable" class="set-con set-con-switch">
		<p class="set-con-desc">
			<label class="tip-lbl">{%label.UPnP%}</label>
			<span id="UpnpSwitch" class="switch">
				<i class="switch-circle icon_select_off"></i>
			</span>
		</p>
	</ul>
	<div id="UpnpTab" class="tab-con hidden">
		<table  id="UpnpTable" class="set-con">
			<tr class="boder-tr">
				<th class="set-con-long">{%label.UpnpSerDesc%}</th>
				<th class="set-con-short">{%label.portType%}</th>
				<th class="set-con-short">{%label.UpnpExPort%}</th>
				<th class="set-con-short">{%label.UpnpInPort%}</th>
				<th class="set-con-long">{%label.UpnpIpAddr%}</th>
				<th class="set-con-short">{%label.UpnpState%}</th>
			</tr>
		</table>
	</div>
</div>
